8 * Class for viewing MediaWiki article and history.
10 * This maintains WikiPage functions for backwards compatibility.
12 * @TODO: move and rewrite code to an Action class
14 * See design.txt for an overview.
15 * Note: edit user interface and cache support functions have been
16 * moved to separate EditPage and HTMLFileCache classes.
18 * @internal documentation reviewed 15 Mar 2010
20 class Article
extends Page
{
36 * @var ParserOptions: ParserOptions object for $wgUser articles
38 public $mParserOptions;
40 var $mContent; // !< #BC cruft
48 var $mContentLoaded = false; // !<
54 var $mRedirectedFrom = null;
57 * @var mixed: boolean false or URL string
59 var $mRedirectUrl = false; // !<
60 var $mRevIdFetched = 0; // !<
65 var $mRevision = null;
75 * Constructor and clear the article
76 * @param $title Title Reference to a Title object.
77 * @param $oldId Integer revision ID, null to fetch from request, zero for current
79 public function __construct( Title
$title, $oldId = null ) {
80 $this->mOldId
= $oldId;
81 $this->mPage
= $this->newPage( $title );
88 protected function newPage( Title
$title ) {
89 return new WikiPage( $title );
93 * Constructor from a page id
94 * @param $id Int article ID to load
95 * @return Article|null
97 public static function newFromID( $id ) {
98 $t = Title
::newFromID( $id );
99 # @todo FIXME: Doesn't inherit right
100 return $t == null ?
null : new self( $t );
101 # return $t == null ? null : new static( $t ); // PHP 5.3
105 * Create an Article object of the appropriate class for the given page.
107 * @param $title Title
108 * @param $context IContextSource
109 * @return Article object
111 public static function newFromTitle( $title, IContextSource
$context ) {
112 if ( NS_MEDIA
== $title->getNamespace() ) {
113 // FIXME: where should this go?
114 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
118 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
120 switch( $title->getNamespace() ) {
122 $page = new ImagePage( $title );
125 $page = new CategoryPage( $title );
128 $page = new Article( $title );
131 $page->setContext( $context );
137 * Create an Article object of the appropriate class for the given page.
139 * @param $page WikiPage
140 * @param $context IContextSource
141 * @return Article object
143 public static function newFromWikiPage( WikiPage
$page, IContextSource
$context ) {
144 $article = self
::newFromTitle( $page->getTitle(), $context );
145 $article->mPage
= $page; // override to keep process cached vars
150 * Tell the page view functions that this view was redirected
151 * from another page on the wiki.
152 * @param $from Title object.
154 public function setRedirectedFrom( Title
$from ) {
155 $this->mRedirectedFrom
= $from;
159 * Get the title object of the article
161 * @return Title object of this page
163 public function getTitle() {
164 return $this->mPage
->getTitle();
168 * Get the WikiPage object of this instance
173 public function getPage() {
180 public function clear() {
181 $this->mContentLoaded
= false;
183 $this->mRedirectedFrom
= null; # Title object if set
184 $this->mRevIdFetched
= 0;
185 $this->mRedirectUrl
= false;
187 $this->mPage
->clear();
191 * Note that getContent/loadContent do not follow redirects anymore.
192 * If you need to fetch redirectable content easily, try
193 * the shortcut in WikiPage::getRedirectTarget()
195 * This function has side effects! Do not use this function if you
196 * only want the real revision text if any.
198 * @deprecated in 1.WD; use getContentObject() instead
200 * @return string Return the text of this revision
202 public function getContent() {
203 wfDeprecated( __METHOD__
, '1.WD' );
204 $content = $this->getContentObject();
205 return ContentHandler
::getContentText( $content );
209 * Returns a Content object representing the pages effective display content,
210 * not necessarily the revision's content!
212 * Note that getContent/loadContent do not follow redirects anymore.
213 * If you need to fetch redirectable content easily, try
214 * the shortcut in WikiPage::getRedirectTarget()
216 * This function has side effects! Do not use this function if you
217 * only want the real revision text if any.
219 * @return Content Return the content of this revision
223 protected function getContentObject() {
225 wfProfileIn( __METHOD__
);
227 if ( $this->mPage
->getID() === 0 ) {
228 # If this is a MediaWiki:x message, then load the messages
229 # and return the message value for x.
230 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
231 $text = $this->getTitle()->getDefaultMessageText();
232 if ( $text === false ) {
236 $content = ContentHandler
::makeContent( $text, $this->getTitle() );
238 $content = new MessageContent( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', null, 'parsemag' );
240 wfProfileOut( __METHOD__
);
244 $this->fetchContentObject();
245 wfProfileOut( __METHOD__
);
247 return $this->mContentObject
;
252 * @return int The oldid of the article that is to be shown, 0 for the
255 public function getOldID() {
256 if ( is_null( $this->mOldId
) ) {
257 $this->mOldId
= $this->getOldIDFromRequest();
260 return $this->mOldId
;
264 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
266 * @return int The old id for the request
268 public function getOldIDFromRequest() {
269 $this->mRedirectUrl
= false;
271 $request = $this->getContext()->getRequest();
272 $oldid = $request->getIntOrNull( 'oldid' );
274 if ( $oldid === null ) {
278 if ( $oldid !== 0 ) {
279 # Load the given revision and check whether the page is another one.
280 # In that case, update this instance to reflect the change.
281 if ( $oldid === $this->mPage
->getLatest() ) {
282 $this->mRevision
= $this->mPage
->getRevision();
284 $this->mRevision
= Revision
::newFromId( $oldid );
285 if ( $this->mRevision
!== null ) {
286 // Revision title doesn't match the page title given?
287 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
288 $function = array( get_class( $this->mPage
), 'newFromID' );
289 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
295 if ( $request->getVal( 'direction' ) == 'next' ) {
296 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
299 $this->mRevision
= null;
301 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
303 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
304 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
307 $this->mRevision
= null;
315 * Load the revision (including text) into this object
317 * @deprecated in 1.19; use fetchContent()
319 function loadContent() {
320 wfDeprecated( __METHOD__
, '1.19' );
321 $this->fetchContent();
325 * Get text of an article from database
326 * Does *NOT* follow redirects.
329 * @note this is really internal functionality that should really NOT be used by other functions. For accessing
330 * article content, use the WikiPage class, especially WikiBase::getContent(). However, a lot of legacy code
331 * uses this method to retrieve page text from the database, so the function has to remain public for now.
333 * @return mixed string containing article contents, or false if null
334 * @deprecated in 1.WD, use WikiPage::getContent() instead
336 function fetchContent() { #BC cruft!
337 wfDeprecated( __METHOD__
, '1.WD' );
339 if ( $this->mContentLoaded
&& $this->mContent
) {
340 return $this->mContent
;
343 wfProfileIn( __METHOD__
);
345 $content = $this->fetchContentObject();
347 $this->mContent
= ContentHandler
::getContentText( $content ); #@todo: get rid of mContent everywhere!
348 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) ); #BC cruft! #XXX: can we deprecate that hook?
350 wfProfileOut( __METHOD__
);
352 return $this->mContent
;
357 * Get text content object
358 * Does *NOT* follow redirects.
359 * TODO: when is this null?
361 * @note code that wants to retrieve page content from the database should use WikiPage::getContent().
363 * @return Content|null
367 protected function fetchContentObject() {
368 if ( $this->mContentLoaded
) {
369 return $this->mContentObject
;
372 wfProfileIn( __METHOD__
);
374 $this->mContentLoaded
= true;
375 $this->mContent
= null;
377 $oldid = $this->getOldID();
379 # Pre-fill content with error message so that if something
380 # fails we'll have something telling us what we intended.
381 $t = $this->getTitle()->getPrefixedText();
382 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
383 $this->mContentObject
= new MessageContent( 'missing-article', array($t, $d), array() ) ; // @todo: this isn't page content but a UI message. horrible.
386 # $this->mRevision might already be fetched by getOldIDFromRequest()
387 if ( !$this->mRevision
) {
388 $this->mRevision
= Revision
::newFromId( $oldid );
389 if ( !$this->mRevision
) {
390 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
391 wfProfileOut( __METHOD__
);
396 if ( !$this->mPage
->getLatest() ) {
397 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
398 wfProfileOut( __METHOD__
);
402 $this->mRevision
= $this->mPage
->getRevision();
404 if ( !$this->mRevision
) {
405 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
406 wfProfileOut( __METHOD__
);
411 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
412 // We should instead work with the Revision object when we need it...
413 $this->mContentObject
= $this->mRevision
->getContent( Revision
::FOR_THIS_USER
); // Loads if user is allowed
414 $this->mRevIdFetched
= $this->mRevision
->getId();
416 wfRunHooks( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject
) );
418 wfProfileOut( __METHOD__
);
420 return $this->mContentObject
;
425 * @deprecated since 1.18
427 public function forUpdate() {
428 wfDeprecated( __METHOD__
, '1.18' );
432 * Returns true if the currently-referenced revision is the current edit
433 * to this page (and it exists).
436 public function isCurrent() {
437 # If no oldid, this is the current version.
438 if ( $this->getOldID() == 0 ) {
442 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
446 * Get the fetched Revision object depending on request parameters or null
450 * @return Revision|null
452 public function getRevisionFetched() {
453 $this->fetchContentObject();
455 return $this->mRevision
;
459 * Use this to fetch the rev ID used on page views
461 * @return int revision ID of last article revision
463 public function getRevIdFetched() {
464 if ( $this->mRevIdFetched
) {
465 return $this->mRevIdFetched
;
467 return $this->mPage
->getLatest();
472 * This is the default action of the index.php entry point: just view the
473 * page of the given title.
475 public function view() {
476 global $wgParser, $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
478 wfProfileIn( __METHOD__
);
480 # Get variables from query string
481 # As side effect this will load the revision and update the title
482 # in a revision ID is passed in the request, so this should remain
483 # the first call of this method even if $oldid is used way below.
484 $oldid = $this->getOldID();
486 $user = $this->getContext()->getUser();
487 # Another whitelist check in case getOldID() is altering the title
488 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
489 if ( count( $permErrors ) ) {
490 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
491 wfProfileOut( __METHOD__
);
492 throw new PermissionsError( 'read', $permErrors );
495 $outputPage = $this->getContext()->getOutput();
496 # getOldID() may as well want us to redirect somewhere else
497 if ( $this->mRedirectUrl
) {
498 $outputPage->redirect( $this->mRedirectUrl
);
499 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
500 wfProfileOut( __METHOD__
);
505 # If we got diff in the query, we want to see a diff page instead of the article.
506 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
507 wfDebug( __METHOD__
. ": showing diff page\n" );
508 $this->showDiffPage();
509 wfProfileOut( __METHOD__
);
514 # Set page title (may be overridden by DISPLAYTITLE)
515 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
517 $outputPage->setArticleFlag( true );
518 # Allow frames by default
519 $outputPage->allowClickjacking();
521 $parserCache = ParserCache
::singleton();
523 $parserOptions = $this->getParserOptions();
524 # Render printable version, use printable version cache
525 if ( $outputPage->isPrintable() ) {
526 $parserOptions->setIsPrintable( true );
527 $parserOptions->setEditSection( false );
528 } elseif ( !$this->isCurrent() ||
!$this->getTitle()->quickUserCan( 'edit' ) ) {
529 $parserOptions->setEditSection( false );
532 # Try client and file cache
533 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
535 $outputPage->setETag( $parserCache->getETag( $this, $parserOptions ) );
538 # Is it client cached?
539 if ( $outputPage->checkLastModified( $this->mPage
->getTouched() ) ) {
540 wfDebug( __METHOD__
. ": done 304\n" );
541 wfProfileOut( __METHOD__
);
545 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
546 wfDebug( __METHOD__
. ": done file cache\n" );
547 # tell wgOut that output is taken care of
548 $outputPage->disable();
549 $this->mPage
->doViewUpdates( $user );
550 wfProfileOut( __METHOD__
);
556 # Should the parser cache be used?
557 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
558 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
559 if ( $user->getStubThreshold() ) {
560 wfIncrStats( 'pcache_miss_stub' );
563 $this->showRedirectedFromHeader();
564 $this->showNamespaceHeader();
566 # Iterate through the possible ways of constructing the output text.
567 # Keep going until $outputDone is set, or we run out of things to do.
570 $this->mParserOutput
= false;
572 while ( !$outputDone && ++
$pass ) {
575 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
578 # Early abort if the page doesn't exist
579 if ( !$this->mPage
->exists() ) {
580 wfDebug( __METHOD__
. ": showing missing article\n" );
581 $this->showMissingArticle();
582 wfProfileOut( __METHOD__
);
586 # Try the parser cache
587 if ( $useParserCache ) {
588 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
590 if ( $this->mParserOutput
!== false ) {
592 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
593 $this->setOldSubtitle( $oldid );
595 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
597 $outputPage->addParserOutput( $this->mParserOutput
);
598 # Ensure that UI elements requiring revision ID have
599 # the correct version information.
600 $outputPage->setRevisionId( $this->mPage
->getLatest() );
601 # Preload timestamp to avoid a DB hit
602 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
603 if ( $cachedTimestamp !== null ) {
604 $outputPage->setRevisionTimestamp( $cachedTimestamp );
605 $this->mPage
->setTimestamp( $cachedTimestamp );
612 # This will set $this->mRevision if needed
613 $this->fetchContentObject();
615 # Are we looking at an old revision
616 if ( $oldid && $this->mRevision
) {
617 $this->setOldSubtitle( $oldid );
619 if ( !$this->showDeletedRevisionHeader() ) {
620 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
621 wfProfileOut( __METHOD__
);
626 # Ensure that UI elements requiring revision ID have
627 # the correct version information.
628 $outputPage->setRevisionId( $this->getRevIdFetched() );
629 # Preload timestamp to avoid a DB hit
630 $outputPage->setRevisionTimestamp( $this->getTimestamp() );
632 # Pages containing custom CSS or JavaScript get special treatment
633 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
634 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
635 $this->showCssOrJsPage();
637 } elseif( !wfRunHooks( 'ArticleContentViewCustom', array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
638 # Allow extensions do their own custom view for certain pages
640 } elseif( Hooks
::isRegistered( 'ArticleViewCustom' ) && !wfRunHooks( 'ArticleViewCustom', array( $this->fetchContent(), $this->getTitle(), $outputPage ) ) ) { #FIXME: fetchContent() is deprecated!
641 # Allow extensions do their own custom view for certain pages
644 $content = $this->getContentObject();
645 $rt = $content->getRedirectChain();
647 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
648 # Viewing a redirect page (e.g. with parameter redirect=no)
649 $outputPage->addHTML( $this->viewRedirect( $rt ) );
650 # Parse just to get categories, displaytitle, etc.
651 $this->mParserOutput
= $content->getParserOutput( $this->getTitle(), $oldid, $parserOptions, false );
652 $outputPage->addParserOutputNoText( $this->mParserOutput
);
658 # Run the parse, protected by a pool counter
659 wfDebug( __METHOD__
. ": doing uncached parse\n" );
661 // @todo: shouldn't we be passing $this->getPage() to PoolWorkArticleView instead of plain $this?
662 $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
663 $this->getRevIdFetched(), $useParserCache, $this->getContentObject(), $this->getContext() );
665 if ( !$poolArticleView->execute() ) {
666 $error = $poolArticleView->getError();
668 $outputPage->clearHTML(); // for release() errors
669 $outputPage->enableClientCache( false );
670 $outputPage->setRobotPolicy( 'noindex,nofollow' );
672 $errortext = $error->getWikiText( false, 'view-pool-error' );
673 $outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
675 # Connection or timeout error
676 wfProfileOut( __METHOD__
);
680 $this->mParserOutput
= $poolArticleView->getParserOutput();
681 $outputPage->addParserOutput( $this->mParserOutput
);
683 # Don't cache a dirty ParserOutput object
684 if ( $poolArticleView->getIsDirty() ) {
685 $outputPage->setSquidMaxage( 0 );
686 $outputPage->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
691 # Should be unreachable, but just in case...
697 # Get the ParserOutput actually *displayed* here.
698 # Note that $this->mParserOutput is the *current* version output.
699 $pOutput = ( $outputDone instanceof ParserOutput
)
700 ?
$outputDone // object fetched by hook
701 : $this->mParserOutput
;
703 # Adjust title for main page & pages with displaytitle
705 $this->adjustDisplayTitle( $pOutput );
708 # For the main page, overwrite the <title> element with the con-
709 # tents of 'pagetitle-view-mainpage' instead of the default (if
711 # This message always exists because it is in the i18n files
712 if ( $this->getTitle()->isMainPage() ) {
713 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
714 if ( !$msg->isDisabled() ) {
715 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
719 # Check for any __NOINDEX__ tags on the page using $pOutput
720 $policy = $this->getRobotPolicy( 'view', $pOutput );
721 $outputPage->setIndexPolicy( $policy['index'] );
722 $outputPage->setFollowPolicy( $policy['follow'] );
724 $this->showViewFooter();
725 $this->mPage
->doViewUpdates( $user );
727 wfProfileOut( __METHOD__
);
731 * Adjust title for pages with displaytitle, -{T|}- or language conversion
732 * @param $pOutput ParserOutput
734 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
735 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
736 $titleText = $pOutput->getTitleText();
737 if ( strval( $titleText ) !== '' ) {
738 $this->getContext()->getOutput()->setPageTitle( $titleText );
743 * Show a diff page according to current request variables. For use within
744 * Article::view() only, other callers should use the DifferenceEngine class.
746 public function showDiffPage() {
747 $request = $this->getContext()->getRequest();
748 $user = $this->getContext()->getUser();
749 $diff = $request->getVal( 'diff' );
750 $rcid = $request->getVal( 'rcid' );
751 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
752 $purge = $request->getVal( 'action' ) == 'purge';
753 $unhide = $request->getInt( 'unhide' ) == 1;
754 $oldid = $this->getOldID();
756 $contentHandler = ContentHandler
::getForTitle( $this->getTitle() );
757 $de = $contentHandler->createDifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
759 // DifferenceEngine directly fetched the revision:
760 $this->mRevIdFetched
= $de->mNewid
;
761 $de->showDiffPage( $diffOnly );
763 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
764 # Run view updates for current revision only
765 $this->mPage
->doViewUpdates( $user );
770 * Show a page view for a page formatted as CSS or JavaScript. To be called by
771 * Article::view() only.
773 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
776 protected function showCssOrJsPage( $showCacheHint = true ) {
779 if ( $showCacheHint ) {
780 $dir = $this->getContext()->getLanguage()->getDir();
781 $lang = $this->getContext()->getLanguage()->getCode();
783 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
787 // Give hooks a chance to customise the output
788 if ( !Hooks
::isRegistered('ShowRawCssJs') ||
wfRunHooks( 'ShowRawCssJs', array( $this->fetchContent(), $this->getTitle(), $wgOut ) ) ) { #FIXME: fetchContent() is deprecated
789 $po = $this->mContentObject
->getParserOutput( $this->getTitle() );
790 $wgOut->addHTML( $po->getText() );
795 * Get the robot policy to be used for the current view
796 * @param $action String the action= GET parameter
797 * @param $pOutput ParserOutput
798 * @return Array the policy that should be set
799 * TODO: actions other than 'view'
801 public function getRobotPolicy( $action, $pOutput ) {
802 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
804 $ns = $this->getTitle()->getNamespace();
806 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
807 # Don't index user and user talk pages for blocked users (bug 11443)
808 if ( !$this->getTitle()->isSubpage() ) {
809 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
811 'index' => 'noindex',
812 'follow' => 'nofollow'
818 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
819 # Non-articles (special pages etc), and old revisions
821 'index' => 'noindex',
822 'follow' => 'nofollow'
824 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
825 # Discourage indexing of printable versions, but encourage following
827 'index' => 'noindex',
830 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
831 # For ?curid=x urls, disallow indexing
833 'index' => 'noindex',
838 # Otherwise, construct the policy based on the various config variables.
839 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
841 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
842 # Honour customised robot policies for this namespace
843 $policy = array_merge(
845 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
848 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
849 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
850 # a final sanity check that we have really got the parser output.
851 $policy = array_merge(
853 array( 'index' => $pOutput->getIndexPolicy() )
857 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
858 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
859 $policy = array_merge(
861 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
869 * Converts a String robot policy into an associative array, to allow
870 * merging of several policies using array_merge().
871 * @param $policy Mixed, returns empty array on null/false/'', transparent
872 * to already-converted arrays, converts String.
873 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
875 public static function formatRobotPolicy( $policy ) {
876 if ( is_array( $policy ) ) {
878 } elseif ( !$policy ) {
882 $policy = explode( ',', $policy );
883 $policy = array_map( 'trim', $policy );
886 foreach ( $policy as $var ) {
887 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
888 $arr['index'] = $var;
889 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
890 $arr['follow'] = $var;
898 * If this request is a redirect view, send "redirected from" subtitle to
899 * the output. Returns true if the header was needed, false if this is not
900 * a redirect view. Handles both local and remote redirects.
904 public function showRedirectedFromHeader() {
905 global $wgRedirectSources;
906 $outputPage = $this->getContext()->getOutput();
908 $rdfrom = $this->getContext()->getRequest()->getVal( 'rdfrom' );
910 if ( isset( $this->mRedirectedFrom
) ) {
911 // This is an internally redirected page view.
912 // We'll need a backlink to the source page for navigation.
913 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
914 $redir = Linker
::linkKnown(
915 $this->mRedirectedFrom
,
918 array( 'redirect' => 'no' )
921 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
923 // Set the fragment if one was specified in the redirect
924 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
925 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
926 $outputPage->addInlineScript( "redirectToFragment(\"$fragment\");" );
929 // Add a <link rel="canonical"> tag
930 $outputPage->addLink( array( 'rel' => 'canonical',
931 'href' => $this->getTitle()->getLocalURL() )
934 // Tell the output object that the user arrived at this article through a redirect
935 $outputPage->setRedirectedFrom( $this->mRedirectedFrom
);
939 } elseif ( $rdfrom ) {
940 // This is an externally redirected view, from some other wiki.
941 // If it was reported from a trusted site, supply a backlink.
942 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
943 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
944 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
954 * Show a header specific to the namespace currently being viewed, like
955 * [[MediaWiki:Talkpagetext]]. For Article::view().
957 public function showNamespaceHeader() {
958 if ( $this->getTitle()->isTalkPage() ) {
959 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
960 $this->getContext()->getOutput()->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
966 * Show the footer section of an ordinary page view
968 public function showViewFooter() {
969 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
970 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
971 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
974 # If we have been passed an &rcid= parameter, we want to give the user a
975 # chance to mark this new article as patrolled.
976 $this->showPatrolFooter();
978 wfRunHooks( 'ArticleViewFooter', array( $this ) );
983 * If patrol is possible, output a patrol UI box. This is called from the
984 * footer section of ordinary page views. If patrol is not possible or not
985 * desired, does nothing.
987 public function showPatrolFooter() {
988 $request = $this->getContext()->getRequest();
989 $outputPage = $this->getContext()->getOutput();
990 $user = $this->getContext()->getUser();
991 $rcid = $request->getVal( 'rcid' );
993 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
997 $token = $user->getEditToken( $rcid );
998 $outputPage->preventClickjacking();
1000 $outputPage->addHTML(
1001 "<div class='patrollink'>" .
1003 'markaspatrolledlink',
1006 wfMsgHtml( 'markaspatrolledtext' ),
1009 'action' => 'markpatrolled',
1013 array( 'known', 'noclasses' )
1021 * Show the error text for a missing article. For articles in the MediaWiki
1022 * namespace, show the default message text. To be called from Article::view().
1024 public function showMissingArticle() {
1025 global $wgSend404Code;
1026 $outputPage = $this->getContext()->getOutput();
1028 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1029 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
1030 $parts = explode( '/', $this->getTitle()->getText() );
1031 $rootPart = $parts[0];
1032 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
1033 $ip = User
::isIP( $rootPart );
1035 if ( !($user && $user->isLoggedIn()) && !$ip ) { # User does not exist
1036 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1037 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1038 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
1039 LogEventsList
::showLogExtract(
1042 $user->getUserPage()->getPrefixedText(),
1046 'showIfEmpty' => false,
1048 'blocked-notice-logextract',
1049 $user->getName() # Support GENDER in notice
1056 wfRunHooks( 'ShowMissingArticle', array( $this ) );
1058 # Show delete and move logs
1059 LogEventsList
::showLogExtract( $outputPage, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
1061 'conds' => array( "log_action != 'revision'" ),
1062 'showIfEmpty' => false,
1063 'msgKey' => array( 'moveddeleted-notice' ) )
1066 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code ) {
1067 // If there's no backing content, send a 404 Not Found
1068 // for better machine handling of broken links.
1069 $this->getContext()->getRequest()->response()->header( "HTTP/1.1 404 Not Found" );
1072 $hookResult = wfRunHooks( 'BeforeDisplayNoArticleText', array( $this ) );
1074 if ( ! $hookResult ) {
1078 # Show error message
1079 $oldid = $this->getOldID();
1081 $text = wfMsgNoTrans( 'missing-article',
1082 $this->getTitle()->getPrefixedText(),
1083 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
1084 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
1085 // Use the default message text
1086 $text = $this->getTitle()->getDefaultMessageText();
1088 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $this->getContext()->getUser() );
1089 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $this->getContext()->getUser() );
1090 $errors = array_merge( $createErrors, $editErrors );
1092 if ( !count( $errors ) ) {
1093 $text = wfMsgNoTrans( 'noarticletext' );
1095 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
1098 $text = "<div class='noarticletext'>\n$text\n</div>";
1100 $outputPage->addWikiText( $text );
1104 * If the revision requested for view is deleted, check permissions.
1105 * Send either an error message or a warning header to the output.
1107 * @return boolean true if the view is allowed, false if not.
1109 public function showDeletedRevisionHeader() {
1110 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1115 $outputPage = $this->getContext()->getOutput();
1116 // If the user is not allowed to see it...
1117 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1118 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1119 'rev-deleted-text-permission' );
1122 // If the user needs to confirm that they want to see it...
1123 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1124 # Give explanation and add a link to view the revision...
1125 $oldid = intval( $this->getOldID() );
1126 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
1127 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1128 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1129 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1130 array( $msg, $link ) );
1133 // We are allowed to see...
1135 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1136 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1137 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1144 * Generate the navigation links when browsing through an article revisions
1145 * It shows the information as:
1146 * Revision as of \<date\>; view current revision
1147 * \<- Previous version | Next Version -\>
1149 * @param $oldid int: revision ID of this article revision
1151 public function setOldSubtitle( $oldid = 0 ) {
1152 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1156 $unhide = $this->getContext()->getRequest()->getInt( 'unhide' ) == 1;
1158 # Cascade unhide param in links for easy deletion browsing
1159 $extraParams = array();
1161 $extraParams['unhide'] = 1;
1164 if ( $this->mRevision
&& $this->mRevision
->getId() === $oldid ) {
1165 $revision = $this->mRevision
;
1167 $revision = Revision
::newFromId( $oldid );
1170 $timestamp = $revision->getTimestamp();
1172 $current = ( $oldid == $this->mPage
->getLatest() );
1173 $language = $this->getContext()->getLanguage();
1174 $td = $language->timeanddate( $timestamp, true );
1175 $tddate = $language->date( $timestamp, true );
1176 $tdtime = $language->time( $timestamp, true );
1178 # Show user links if allowed to see them. If hidden, then show them only if requested...
1179 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1181 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1182 ?
'revision-info-current'
1185 $outputPage = $this->getContext()->getOutput();
1186 $outputPage->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1187 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1188 $tdtime, $revision->getUser() )->parse() . "</div>" );
1191 ?
wfMsgHtml( 'currentrevisionlink' )
1194 wfMsgHtml( 'currentrevisionlink' ),
1197 array( 'known', 'noclasses' )
1200 ?
wfMsgHtml( 'diff' )
1203 wfMsgHtml( 'diff' ),
1209 array( 'known', 'noclasses' )
1211 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1215 wfMsgHtml( 'previousrevision' ),
1218 'direction' => 'prev',
1221 array( 'known', 'noclasses' )
1223 : wfMsgHtml( 'previousrevision' );
1227 wfMsgHtml( 'diff' ),
1233 array( 'known', 'noclasses' )
1235 : wfMsgHtml( 'diff' );
1236 $nextlink = $current
1237 ?
wfMsgHtml( 'nextrevision' )
1240 wfMsgHtml( 'nextrevision' ),
1243 'direction' => 'next',
1246 array( 'known', 'noclasses' )
1248 $nextdiff = $current
1249 ?
wfMsgHtml( 'diff' )
1252 wfMsgHtml( 'diff' ),
1258 array( 'known', 'noclasses' )
1261 $cdel = Linker
::getRevDeleteLink( $this->getContext()->getUser(), $revision, $this->getTitle() );
1262 if ( $cdel !== '' ) {
1266 $outputPage->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1267 wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1268 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>" );
1274 * @param $target Title|Array of destination(s) to redirect
1275 * @param $appendSubtitle Boolean [optional]
1276 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1277 * @return string containing HMTL with redirect link
1279 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1280 global $wgStylePath;
1282 if ( !is_array( $target ) ) {
1283 $target = array( $target );
1286 $lang = $this->getTitle()->getPageLanguage();
1287 $imageDir = $lang->getDir();
1289 if ( $appendSubtitle ) {
1290 $this->getContext()->getOutput()->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1293 // the loop prepends the arrow image before the link, so the first case needs to be outside
1298 $title = array_shift( $target );
1300 if ( $forceKnown ) {
1301 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1303 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1306 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1307 $alt = $lang->isRTL() ?
'←' : '→';
1308 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1309 foreach ( $target as $rt ) {
1310 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1311 if ( $forceKnown ) {
1312 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1314 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1318 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1319 return '<div class="redirectMsg">' .
1320 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1321 '<span class="redirectText">' . $link . '</span></div>';
1325 * Handle action=render
1327 public function render() {
1328 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1333 * action=protect handler
1335 public function protect() {
1336 $form = new ProtectionForm( $this );
1341 * action=unprotect handler (alias)
1343 public function unprotect() {
1348 * UI entry point for page deletion
1350 public function delete() {
1351 # This code desperately needs to be totally rewritten
1353 $title = $this->getTitle();
1354 $user = $this->getContext()->getUser();
1357 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1358 if ( count( $permission_errors ) ) {
1359 throw new PermissionsError( 'delete', $permission_errors );
1362 # Read-only check...
1363 if ( wfReadOnly() ) {
1364 throw new ReadOnlyError
;
1367 # Better double-check that it hasn't been deleted yet!
1368 $dbw = wfGetDB( DB_MASTER
);
1369 $conds = $title->pageCond();
1370 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1371 if ( $latest === false ) {
1372 $outputPage = $this->getContext()->getOutput();
1373 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1374 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1375 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1377 $outputPage->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1378 LogEventsList
::showLogExtract(
1381 $title->getPrefixedText()
1387 $request = $this->getContext()->getRequest();
1388 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1389 $deleteReason = $request->getText( 'wpReason' );
1391 if ( $deleteReasonList == 'other' ) {
1392 $reason = $deleteReason;
1393 } elseif ( $deleteReason != '' ) {
1394 // Entry from drop down menu + additional comment
1395 $reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
1397 $reason = $deleteReasonList;
1400 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1401 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1403 # Flag to hide all contents of the archived revisions
1404 $suppress = $request->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1406 $this->doDelete( $reason, $suppress );
1408 if ( $request->getCheck( 'wpWatch' ) && $user->isLoggedIn() ) {
1410 } elseif ( $title->userIsWatching() ) {
1417 // Generate deletion reason
1418 $hasHistory = false;
1421 $reason = $this->generateReason( $hasHistory );
1422 } catch (MWException
$e) {
1423 # if a page is horribly broken, we still want to be able to delete it. so be lenient about errors here.
1424 wfDebug("Error while building auto delete summary: $e");
1429 // If the page has a history, insert a warning
1430 if ( $hasHistory ) {
1431 $revisions = $this->mTitle
->estimateRevisionCount();
1432 // @todo FIXME: i18n issue/patchwork message
1433 $this->getContext()->getOutput()->addHTML( '<strong class="mw-delete-warning-revisions">' .
1434 wfMsgExt( 'historywarning', array( 'parseinline' ), $this->getContext()->getLanguage()->formatNum( $revisions ) ) .
1435 wfMsgHtml( 'word-separator' ) . Linker
::link( $title,
1436 wfMsgHtml( 'history' ),
1437 array( 'rel' => 'archives' ),
1438 array( 'action' => 'history' ) ) .
1442 if ( $this->mTitle
->isBigDeletion() ) {
1443 global $wgDeleteRevisionsLimit;
1444 $this->getContext()->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1445 array( 'delete-warning-toobig', $this->getContext()->getLanguage()->formatNum( $wgDeleteRevisionsLimit ) ) );
1449 return $this->confirmDelete( $reason );
1453 * Output deletion confirmation dialog
1454 * @todo FIXME: Move to another file?
1455 * @param $reason String: prefilled reason
1457 public function confirmDelete( $reason ) {
1458 wfDebug( "Article::confirmDelete\n" );
1460 $outputPage = $this->getContext()->getOutput();
1461 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1462 $outputPage->addBacklinkSubtitle( $this->getTitle() );
1463 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1464 $outputPage->addWikiMsg( 'confirmdeletetext' );
1466 wfRunHooks( 'ArticleConfirmDelete', array( $this, $outputPage, &$reason ) );
1468 $user = $this->getContext()->getUser();
1470 if ( $user->isAllowed( 'suppressrevision' ) ) {
1471 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1473 <td class='mw-input'><strong>" .
1474 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1475 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1481 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1483 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1484 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1485 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1486 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1487 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1488 "<tr id=\"wpDeleteReasonListRow\">
1489 <td class='mw-label'>" .
1490 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1492 <td class='mw-input'>" .
1493 Xml
::listDropDown( 'wpDeleteReasonList',
1494 wfMsgForContent( 'deletereason-dropdown' ),
1495 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1498 <tr id=\"wpDeleteReasonRow\">
1499 <td class='mw-label'>" .
1500 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1502 <td class='mw-input'>" .
1503 Html
::input( 'wpReason', $reason, 'text', array(
1505 'maxlength' => '255',
1513 # Disallow watching if user is not logged in
1514 if ( $user->isLoggedIn() ) {
1518 <td class='mw-input'>" .
1519 Xml
::checkLabel( wfMsg( 'watchthis' ),
1520 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1529 <td class='mw-submit'>" .
1530 Xml
::submitButton( wfMsg( 'deletepage' ),
1531 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1534 Xml
::closeElement( 'table' ) .
1535 Xml
::closeElement( 'fieldset' ) .
1536 Html
::hidden( 'wpEditToken', $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1537 Xml
::closeElement( 'form' );
1539 if ( $user->isAllowed( 'editinterface' ) ) {
1540 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1541 $link = Linker
::link(
1543 wfMsgHtml( 'delete-edit-reasonlist' ),
1545 array( 'action' => 'edit' )
1547 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1550 $outputPage->addHTML( $form );
1551 $outputPage->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1552 LogEventsList
::showLogExtract( $outputPage, 'delete',
1553 $this->getTitle()->getPrefixedText()
1558 * Perform a deletion and output success or failure messages
1560 * @param $suppress bool
1562 public function doDelete( $reason, $suppress = false ) {
1564 $outputPage = $this->getContext()->getOutput();
1565 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, 0, true, $error ) ) {
1566 $deleted = $this->getTitle()->getPrefixedText();
1568 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
1569 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1571 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1573 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1574 $outputPage->returnToMain( false );
1576 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1577 if ( $error == '' ) {
1578 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1579 array( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1581 $outputPage->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1583 LogEventsList
::showLogExtract(
1586 $this->getTitle()->getPrefixedText()
1589 $outputPage->addHTML( $error );
1594 /* Caching functions */
1597 * checkLastModified returns true if it has taken care of all
1598 * output to the client that is necessary for this request.
1599 * (that is, it has sent a cached version of the page)
1601 * @return boolean true if cached version send, false otherwise
1603 protected function tryFileCache() {
1604 static $called = false;
1607 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1612 if ( $this->isFileCacheable() ) {
1613 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1614 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1615 wfDebug( "Article::tryFileCache(): about to load file\n" );
1616 $cache->loadFromFileCache( $this->getContext() );
1619 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1620 ob_start( array( &$cache, 'saveToFileCache' ) );
1623 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1630 * Check if the page can be cached
1633 public function isFileCacheable() {
1636 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1637 $cacheable = $this->mPage
->getID()
1638 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1639 // Extension may have reason to disable file caching on some pages.
1641 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1651 * Lightweight method to get the parser output for a page, checking the parser cache
1652 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1653 * consider, so it's not appropriate to use there.
1655 * @since 1.16 (r52326) for LiquidThreads
1657 * @param $oldid mixed integer Revision ID or null
1658 * @param $user User The relevant user
1659 * @return ParserOutput or false if the given revsion ID is not found
1661 public function getParserOutput( $oldid = null, User
$user = null ) {
1662 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
1663 $parserOptions = $this->mPage
->makeParserOptions( $user );
1665 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1669 * Get parser options suitable for rendering the primary article wikitext
1670 * @return ParserOptions
1672 public function getParserOptions() {
1673 if ( !$this->mParserOptions
) {
1674 $this->mParserOptions
= $this->mPage
->makeParserOptions( $this->getContext()->getUser() );
1676 // Clone to allow modifications of the return value without affecting cache
1677 return clone $this->mParserOptions
;
1681 * Sets the context this Article is executed in
1683 * @param $context IContextSource
1686 public function setContext( $context ) {
1687 $this->mContext
= $context;
1691 * Gets the context this Article is executed in
1693 * @return IContextSource
1696 public function getContext() {
1697 if ( $this->mContext
instanceof IContextSource
) {
1698 return $this->mContext
;
1700 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1701 return RequestContext
::getMain();
1706 * Info about this page
1707 * @deprecated since 1.19
1709 public function info() {
1710 wfDeprecated( __METHOD__
, '1.19' );
1711 Action
::factory( 'info', $this )->show();
1715 * Mark this particular edit/page as patrolled
1716 * @deprecated since 1.18
1718 public function markpatrolled() {
1719 wfDeprecated( __METHOD__
, '1.18' );
1720 Action
::factory( 'markpatrolled', $this )->show();
1724 * Handle action=purge
1725 * @deprecated since 1.19
1727 public function purge() {
1728 return Action
::factory( 'purge', $this )->show();
1732 * Handle action=revert
1733 * @deprecated since 1.19
1735 public function revert() {
1736 wfDeprecated( __METHOD__
, '1.19' );
1737 Action
::factory( 'revert', $this )->show();
1741 * Handle action=rollback
1742 * @deprecated since 1.19
1744 public function rollback() {
1745 wfDeprecated( __METHOD__
, '1.19' );
1746 Action
::factory( 'rollback', $this )->show();
1750 * User-interface handler for the "watch" action.
1751 * Requires Request to pass a token as of 1.18.
1752 * @deprecated since 1.18
1754 public function watch() {
1755 wfDeprecated( __METHOD__
, '1.18' );
1756 Action
::factory( 'watch', $this )->show();
1760 * Add this page to the current user's watchlist
1762 * This is safe to be called multiple times
1764 * @return bool true on successful watch operation
1765 * @deprecated since 1.18
1767 public function doWatch() {
1768 wfDeprecated( __METHOD__
, '1.18' );
1769 return WatchAction
::doWatch( $this->getTitle(), $this->getContext()->getUser() );
1773 * User interface handler for the "unwatch" action.
1774 * Requires Request to pass a token as of 1.18.
1775 * @deprecated since 1.18
1777 public function unwatch() {
1778 wfDeprecated( __METHOD__
, '1.18' );
1779 Action
::factory( 'unwatch', $this )->show();
1783 * Stop watching a page
1784 * @return bool true on successful unwatch
1785 * @deprecated since 1.18
1787 public function doUnwatch() {
1788 wfDeprecated( __METHOD__
, '1.18' );
1789 return WatchAction
::doUnwatch( $this->getTitle(), $this->getContext()->getUser() );
1793 * Output a redirect back to the article.
1794 * This is typically used after an edit.
1796 * @deprecated in 1.18; call OutputPage::redirect() directly
1797 * @param $noRedir Boolean: add redirect=no
1798 * @param $sectionAnchor String: section to redirect to, including "#"
1799 * @param $extraQuery String: extra query params
1801 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1802 wfDeprecated( __METHOD__
, '1.18' );
1804 $query = 'redirect=no';
1806 $query .= "&$extraQuery";
1808 $query = $extraQuery;
1811 $this->getContext()->getOutput()->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1815 * Use PHP's magic __get handler to handle accessing of
1816 * raw WikiPage fields for backwards compatibility.
1818 * @param $fname String Field name
1820 public function __get( $fname ) {
1821 if ( property_exists( $this->mPage
, $fname ) ) {
1822 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1823 return $this->mPage
->$fname;
1825 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1829 * Use PHP's magic __set handler to handle setting of
1830 * raw WikiPage fields for backwards compatibility.
1832 * @param $fname String Field name
1833 * @param $fvalue mixed New value
1835 public function __set( $fname, $fvalue ) {
1836 if ( property_exists( $this->mPage
, $fname ) ) {
1837 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1838 $this->mPage
->$fname = $fvalue;
1839 // Note: extensions may want to toss on new fields
1840 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1841 $this->mPage
->$fname = $fvalue;
1843 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1848 * Use PHP's magic __call handler to transform instance calls to
1849 * WikiPage functions for backwards compatibility.
1851 * @param $fname String Name of called method
1852 * @param $args Array Arguments to the method
1855 public function __call( $fname, $args ) {
1856 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1857 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1858 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1860 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1863 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1866 * @param $limit array
1867 * @param $expiry array
1868 * @param $cascade bool
1869 * @param $reason string
1873 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User
$user ) {
1874 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
1878 * @param $limit array
1879 * @param $reason string
1880 * @param $cascade int
1881 * @param $expiry array
1884 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1885 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1889 * @param $reason string
1890 * @param $suppress bool
1892 * @param $commit bool
1893 * @param $error string
1896 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1897 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1905 * @param $resultDetails
1909 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
1910 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
1911 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1918 * @param $resultDetails
1919 * @param $guser User
1922 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
1923 $guser = is_null( $guser ) ?
$this->getContext()->getUser() : $guser;
1924 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
1928 * @param $hasHistory bool
1931 public function generateReason( &$hasHistory ) {
1932 $title = $this->mPage
->getTitle();
1933 $handler = ContentHandler
::getForTitle( $title );
1934 return $handler->getAutoDeleteReason( $title, $hasHistory );
1937 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
1942 public static function selectFields() {
1943 return WikiPage
::selectFields();
1947 * @param $title Title
1949 public static function onArticleCreate( $title ) {
1950 WikiPage
::onArticleCreate( $title );
1954 * @param $title Title
1956 public static function onArticleDelete( $title ) {
1957 WikiPage
::onArticleDelete( $title );
1961 * @param $title Title
1963 public static function onArticleEdit( $title ) {
1964 WikiPage
::onArticleEdit( $title );
1972 * @deprecated since 1.WD, use ContentHandler::getAutosummary() instead
1974 public static function getAutosummary( $oldtext, $newtext, $flags ) {
1975 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );